<!--
 * @Author: yansheng 610363806@qq.com
 * @Date: 2024-07-15 23:54:39
 * @LastEditors: zhang00001 774004514@qq.com
 * @LastEditTime: 2024-08-02 17:54:26
 * @FilePath: \cell-admin\src\pages\setting\raffle\deliverGoods.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <a-drawer
    :title="editType=='edit'?'改物流':'发货'"
    placement="right"
    :maskClosable="false"
    :keyboard="false"
    width="800"
    v-model:open="showAddDialog"
  >
    <a-form
      ref="formRef"
      :model="formData"
      label-position="top"
    >
      <a-form-item
        label="快递单号"
        :rules="[{ required: true, message: '请输入快递单号' }]"
        required
        name="expressNumber"
      >
        <a-input v-model:value="formData.expressNumber"></a-input>
      </a-form-item>
      <a-form-item :wrapper-col="{ span: 14, offset: 4 }">
        <a-button @click="handleCancel">取消</a-button>
        <!-- :loading="loading" -->
        <a-button style="margin-left:20px ;"
          type="primary"
          @click="handleSubmit"
        >
          确认
        </a-button>
      </a-form-item>
    </a-form>
  </a-drawer>
</template>

<script setup>
  import { message } from 'ant-design-vue'
  import { raffleGoods, orderUpdate } from '@/api/index.js'
  import { ref, defineEmits, defineExpose, defineProps, toRefs, nextTick } from 'vue'
  const emit = defineEmits(['refuData'])
  const showAddDialog = ref(false)
  const detailInfo = ref({})
  const sendType = ref('')
  const editType=ref('') 
  const init = (row, orderType,type) => {
  
    sendType.value = orderType
    showAddDialog.value = true
    detailInfo.value = row
    if(type){
      editType.value=type
      formData.value.expressNumber=row.tracking_number
    }else{
      editType.value=''
      formData.value.expressNumber=''
    }
  
  }
  const formData = ref({
    expressNumber: ''
  })
  const handleSubmit = () => {
    if (sendType.value=='order') {
      orderUpdate({
        tracking_number: formData.value.expressNumber,
        order_id: detailInfo.value.order_id,
        order_status: 1
      })
        .then((res) => {
          if (res.errorCode) {
            message.error(res.msg || '操作失败')
            return
          }
          if (res.code == 200) {
            message.success('操作成功！')
            showAddDialog.value = false
             
            emit('refuData')
          }
        })
        .catch((err) => {
          // message.error(err.msg)
        })
    } else {
      raffleGoods({
        tracking_number: formData.value.expressNumber,
        raffle_record_id: detailInfo.value.raffle_record_id
      })
        .then((res) => {
          if (res.errorCode) {
            message.error(res.msg || '操作失败')
            return
          }
          if (res.code == 200) {
            message.success('操作成功！')
            showAddDialog.value = false
            emit('refuData')
          }
        })
        .catch((err) => {
          message.error(err.msg)
        })
    }
  }
  const handleCancel = () => {
    showAddDialog.value = false
  }
  defineExpose({
    init
  })
</script>
<style scoped lang="less"></style>
